package com.mapmymotion;

import android.app.ListActivity;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.widget.ListAdapter;
import android.widget.SimpleCursorAdapter;

public class ContactDetail extends ListActivity {
	
/** Called when the activity is first created. */

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Cursor mCursor = getContacts();
		startManagingCursor(mCursor);
		// Now create a new list adapter bound to the cursor.
		// SimpleListAdapter is designed for binding to a Cursor.
		ListAdapter adapter = new SimpleCursorAdapter(this, // Context.
				R.layout.list_contacts_details, // Specify the row template
														// to use (here, two
														// columns bound to the
														// two retrieved cursor
														// rows).
				mCursor, // Pass in the cursor to bind to.
				// Array of cursor columns to bind to.
				new String[] { ContactsContract.Contacts._ID,
						ContactsContract.Contacts.DISPLAY_NAME },
				// Parallel array of which template objects to bind to those
				// columns.
				new int[] {R.id.name_entry, R.id.number_entry });

		// Bind to our new adapter.
		setListAdapter(adapter);
	}

	private Cursor getContacts() {
		// Run query
		Uri uri = ContactsContract.Contacts.CONTENT_URI;

		
		String[] projection = new String[] { ContactsContract.Contacts._ID,
				ContactsContract.Contacts.DISPLAY_NAME };


		String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '"
				+ ("1") + "'";
		String[] selectionArgs = null;
		String sortOrder = ContactsContract.Contacts.DISPLAY_NAME
				+ " COLLATE LOCALIZED ASC";

		return managedQuery(uri, projection, selection, selectionArgs,
				sortOrder);
	}

}
/*
import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.Contacts.People;
import android.widget.SimpleCursorAdapter;

// starting the class  
public class ContactDetail extends ListActivity {


	      @Override
	      public void onCreate(Bundle savedInstance) {
	            setContentView(R.layout.list_contacts);

	            // some code

	            Cursor cursor = getContentResolver().query(People.CONTENT_URI, new String[] {People._ID, People.NAME, People.NUMBER}, null, null, null);
	            startManagingCursor(cursor);

	            // the desired columns to be bound
	            String[] columns = new String[] { People.NAME, People.NUMBER };
	            // the XML defined views which the data will be bound to
	            int[] to = new int[] { R.id.name_entry, R.id.number_entry };

	            // create the adapter using the cursor pointing to the desired data as well as the layout information
	            SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this, R.layout.list_contacts_details, cursor, columns, to);

	            // set this adapter as your ListActivity's adapter
	            this.setListAdapter(mAdapter);
	      }
	}

*/